<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="流程名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入参数名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数键名" prop="paramKey">
        <el-input
          v-model="queryParams.paramKey"
          placeholder="请输入参数键名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <div style="float:left"> -->
        <el-upload
          class="upload-demo"
          :action="uploadProcessPath"
          :before-upload="handlebefore"
          :on-success="handleSuccess"
          :headers="headers"
          :file-list="fileList"
          :limit="1">
                  <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传zip文件，且不超过2MB</div>
        </el-upload>
      <!-- </div>
      <div style="float:right">
        <el-button @click="chooseFlow">绑定流程</el-button>
      </div> -->
    </el-row>


    <el-table v-loading="loading" :data="deployList">
      <el-table-column label="ID" prop="id" align="center" />
      <el-table-column label="流程名称" align="center" prop="name" />
      <el-table-column label="流程编号" align="center" prop="key" :show-overflow-tooltip="true" />
      <el-table-column label="流程版本号" align="center" prop="version" :show-overflow-tooltip="true" />
      <el-table-column label="部署编号" align="center" prop="deploymentId" />
      <el-table-column label="资源文件名称" align="center" prop="resourceName" />
      <el-table-column label="是否挂起" align="center" prop="suspensionState" >
        <template slot-scope="scope">
            <el-tag v-if="scope.row.suspensionState==1" type="success">激活</el-tag>
            <el-tag v-if="scope.row.suspensionState==2" type="success">挂起</el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- <el-dialog title="绑定流程" :visible.sync="chooseOpen" width="400px">

      <el-form ref="tieUpForm" :model="tieUpForm" :rules="tieUpRules" label-width="80px">
        <el-form-item label="流程名称" prop="flowDeploymentId">
          <el-select
            v-model="tieUpForm.flowDeploymentId" clearable filterable placeholder="请选择">
            <el-option
              v-for="item in flowOptions"
              :key="item.deploymentId"
              :label="item.name + ':' + item.version"
              :value="item.deploymentId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="流程类型" prop="type">
          <el-select
            v-model="tieUpForm.type" clearable filterable placeholder="请选择">
            <el-option
              v-for="item in typeOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>

      </el-form>


      <div slot="footer" class="dialog-footer" >
        <el-button type="primary" @click="submitChoose">确 定</el-button>
        <el-button @click="cancelChoose">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import {getDeployList,getAllDeployFlow,tieUpTenant} from "@/api/workflow/deploy"

export default {
  name: "Config",
  data() {
    return {
      uploadProcessPath:process.env.VUE_APP_BASE_API + '/workflow/uploadProcessZip',
      headers: { Authorization: "Bearer " + getToken() },
      fileList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 参数表格数据
      deployList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // chooseOpen: false,
      // 类型数据字典
      typeOptions: [],
      // flowOptions:[],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paramName: undefined,
        paramKey: undefined,
        paramType: undefined
      },
      // tieUpForm:{},
      // tieUpRules:{}
    };
  },
  computed: {
    headers() {
      return {
        'Authorization': getToken()
      }
    }
  },
  created() {
    this.getList();
    // getAllDeployFlow().then(resp => {
    //   this.flowOptions = resp.data;
    // })
    // this.getDicts("flow_type").then(response => {
    //   this.typeOptions = response.data;
    // });
  },
  methods: {

    // chooseFlow(){
    //   this.tieUpForm = {};
    //   this.chooseOpen = true;
    // },
    // submitChoose(){
    //   console.log(this.tieUpForm)
    //   tieUpTenant(this.tieUpForm).then(resp => {
    //     if (resp.code === 200){
    //       this.msgSuccess("修改成功");
    //       this.chooseOpen = false;
    //       this.getList(); 
    //     }
    //   })
    // },
    // cancelChoose(){
    //   this.tieUpForm = {};
    //   this.chooseOpen = false
    // },
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      getDeployList(this.queryParams).then(response => {
          this.deployList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        paramName: undefined,
        paramKey: undefined,
        paramValue: undefined,
        paramType: "Y",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handlebefore(file){
        console.log(file)
        let fileName = file.name
        let fileSize = file.size
        const maxSize = 1024*1024*2
        let fileNameIndex = fileName.lastIndexOf(".");
        let fileNameLength = fileName.length;
        let fileFormat = fileName.substring(fileNameIndex);
        debugger
        if(fileFormat.toLowerCase() != '.zip'){
            this.$message('只能上次zip文件,请重新选择');
            return false
        }
        if(maxSize < fileSize){
            this.$message('文件大于2MB,请重新选择');
            return false
        }
    },
    handleSuccess(){
        this.$message({
          message: '上传部署成功',
          type: 'success'
        });
        this.fileList=[]
        this.handleQuery()
    }
  }
};
</script>
